package com.yrmao.yrmtimedialog.ui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yrmao.yrmtimedialog.R;
import com.yrmao.yrmtimedialog.ui.widget.MTimeDialog;
import com.yrmao.yrmtimedialog.ui.widget.interfaces.MTimeOnClickListener;

/***
 * 自定义时间选择器
 * v1.0.0
 * 作者:叶茂
 * 未优化
 */
public class MainActivity extends AppCompatActivity implements MTimeOnClickListener {
    private TextView tv_time;
    private MTimeDialog mTimeDialog = new MTimeDialog(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initview();
    }

    private void initview() {
        tv_time = (TextView) findViewById(R.id.tv_time);
        findViewById(R.id.tv_day).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mTimeDialog.showDayTime();
            }
        });


        findViewById(R.id.tv_month).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mTimeDialog.showMonthTime();
            }
        });
        findViewById(R.id.tv_year).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mTimeDialog.showYearTime();
            }
        });
        mTimeDialog.setMTimeOnClickListener(this);
    }

    @Override
    public void getYear(int year) {//year对话框点击确定时调用
        tv_time.setText(year + "年");
    }

    @Override
    public void getYear_Month(int year, int month) {//month对话框点击确定时调用
        tv_time.setText(year + "年" + month + "月");
    }

    @Override
    public void getYear_Month_Day(int year, int month, int day) {//日期对话框点击确定时调用
        tv_time.setText(year + "年" + month + "月" + day + "日");

    }
}
